<template>
  <div class="contain">
    <div
      class="cards"
      @mouseover="showHover = item.id"
      @mouseout="showHover = null"
      :class="`rarity_wujinag_${item.rarity}`"
    >
      <!-- 武将 -->
      <div style="width: 100%; height: 100%">
        <div class="top">
          <div class="name">{{ item.name }}</div>
          <div class="cost">{{ item.salary }}</div>
        </div>
        <div class="mid">
          <div class="image">
            <van-icon
              :color="
                ['#4bc84b', '#0063c7', '#660066', '#ffa500', '#ff0000'][
                  item.rarity
                ]
              "
              class="iconFont"
              class-prefix="icon"
              size="100"
              :class="item.image"
            />
          </div>
          <div class="ablity">
            <div>{{ item.pow }}</div>
            <div>{{ item.int }}</div>
          </div>
        </div>
        <div class="bottom">
          <div v-show="tactic">战法：{{ tactic.name }}</div>
          <div v-show="stratagem">计谋：{{ stratagem.name }}</div>
          <div v-show="politics">政策：{{ politics.name }}</div>
        </div>
      </div>
      <!-- 武将-悬浮内容 -->
      <div
        v-show="showHover == item.id"
        :style="{
          left: index % 5 == 4 ? '-70%' : '70%',
        }"
        class="map-hover"
      >
        <div class="row" v-show="item.type">
          <span class="title"> 状态：</span> {{ showTextByType(item.type) }}
        </div>
        <div class="row" v-show="tactic">
          <span class="title"> {{ tactic.name }}：</span>{{ tactic.desc }}
        </div>
        <div class="row" v-show="stratagem">
          <span class="title"> {{ stratagem.name }}：</span>
          {{ stratagem.desc }}
        </div>
        <div class="row" v-show="politics">
          <span class="title"> {{ politics.name }}：</span>
          {{ politics.desc }}
        </div>
      </div>
      <div
        v-if="gameContral.setting && item.type == 'normal'"
        class="iconFont desc"
        class-prefix="icon"
        size="100"
      >
        点击添加
      </div>
      <van-icon
        v-else
        class="iconFont water"
        class-prefix="icon"
        size="100"
        :class="`icon-${item.type}`"
      />
    </div>
  </div>
</template>
<script>
import {
  nextPlayer,
  getCurrentPlayerInfo,
  turnStart,
  addLog,
  closePop,
  updateLand,
  buyLand,
  getLocalInfoById,
  getGeneralToPlayer,
} from "@/api/monpoly.js";
export default {
  props: {
    item: {
      type: Object,
      default: () => {
        return {
          id: 999,
          name: "稻草人",
          pow: 1,
          int: 1,
          salary: 50,
          type: "normal",
          tactic_name: "恐惧",
          stratagem_name: "夜割",
          politics_name: "群鸦风暴",
          address_name: "洛阳",
          address: 0,
        };
      },
    },
    index: {
      type: Number,
      default: null,
    },
  },
  mounted() {},
  data() {
    return {
      showHover: 314159,
    };
  },
  computed: {
    gameContral() {
      let res = JSON.parse(JSON.stringify(this.$store.getters.gameContral));
      return res;
    },
    tactic() {
      let res = getLocalInfoById([this.item.tactic], "tactic");
      return res[0] || null;
    },
    stratagem() {
      let res = getLocalInfoById([this.item.stratagem], "stratagem");
      return res[0] || null;
    },
    // command() {
    //   let res = getLocalInfoById([this.item.command], "command");
    //   return res[0]|| null;
    // },
    politics() {
      let res = getLocalInfoById([this.item.politics], "politics");
      return res[0] || null;
    },
    tagList() {
      let res = JSON.parse(JSON.stringify(this.$store.getters.tagList));
      return res;
    },
  },
  methods: {
    showTextByType(type) {
      let str = "";
      /**
       * normal 待命
       * chief 主帅
       * counsellor 军师
       * politics 政策
       * defcity 守城
       */
      if (type == "defcity") {
        str = this.tagList[type] + this.item.address_name;
      } else {
        str = this.tagList[type];
      }
      return str;
    },
  },
};
</script>
<style lang="less" scoped>
.contain {
  border: 2px solid rgba(226, 217, 217, 0.8);
  padding: 10px;
  background-color: rgb(0, 0, 0);
  border-radius: 6px;
  font-size: 30px;
  text-align: center;
  width: 100%;
  height: 100%;
  position: relative;
  .cards {
    background-color: #fff;
    border-radius: 10px;
    width: 100%;
    height: 100%;
  }
}
.water {
  position: absolute;
  right: 0;
  bottom: 10px;
  opacity: 0.5;
}
.desc {
  position: absolute;
  right: 0;
  bottom: 30px;
  opacity: 0.5;
  transform: rotate(-45deg);
  color: chocolate;
  font-weight: bolder;
}
.top {
  height: 15%;
  border: 2px solid #000000;
  border-top-right-radius: 6px;
  border-top-left-radius: 6px;
  display: flex;
  justify-content: space-between;
  .name {
    flex: 1;
  }
  .cost {
    display: inline-block;
    border-left: 2px solid #000000;
    align-self: center;
    min-width: 60px;
    padding: 0 5px;
  }
}
.mid {
  height: 35%;
  border: 2px solid #000000;
  text-align: start;
  display: flex;
  padding: 10px 0 10px 10px;
  .ablity {
    font-size: 50px;
    font-weight: bolder;
    padding: 0 0 0 20px;
    text-align: center;
  }
}
.bottom {
  text-align: start;
  height: calc(50% - 50px);
  border: 2px solid #000000;
  padding: 10px;
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;

  font-size: 20px;
}
.map-hover {
  border: 2px solid #737373;
  position: absolute;
  background-color: #ffffff;
  z-index: 9999;
  width: 100%;
  min-height: 40%;
  top: 70%;
  border-radius: 6px;
  text-align: start;
  padding: 10px;

  font-size: 16px;
  .row {
    padding-bottom: 10px;
    .title {
      font-weight: bolder;
    }
  }
  .row + .row {
    border-top: 0.2px solid #b0b0b0;
    padding-top: 10px;
  }
}
.map-hover::-webkit-scrollbar {
  display: none;
}
</style>
